package com.itheima.web;

import com.itheima.pojo.Result;
import com.itheima.pojo.Role;
import com.itheima.service.RoleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getRoleListServlet")
public class GetRoleListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            RoleService roleService = new RoleService();
            List<Role> roleList = roleService.getRoleList();
            // 封装响应结果,并转成json返回给浏览器
            Result result = new Result(true, "", roleList);
            BaseController.responseJson(response,result);
        } catch (Exception e) {
            e.printStackTrace();
            Result result = new Result(false, "服务器忙,请稍后重试...", null);
            BaseController.responseJson(response,result);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}